package ch02sl.sl.sl7;



import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import javax.xml.parsers.DocumentBuilderFactory;

import java.io.File;

import java.net.MalformedURLException;
import java.util.Iterator;

public class XMLParse {

    public  void showPhoneInfo() {
        Document doc = null;
        try {
            SAXReader saxReader = new SAXReader();
            doc =  saxReader.read(new File("src/test/java/ch02sl/sl6/收藏信息.xml"));
        }
         catch (DocumentException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        Element root =  doc.getRootElement();

        for (Iterator iterator = root.elementIterator(); iterator.hasNext(); ) {
           org.dom4j.Element brandEle = (org.dom4j.Element) iterator.next();
            System.out.println("品牌："+brandEle.attributeValue("name"));
            for (Iterator itType = brandEle.elementIterator();itType.hasNext();){
                Element typeEle = (Element) itType.next();
                System.out.println("\t型号："+typeEle.attributeValue("name"));
            }
        }
    }
    public static void main(String[] args) {
        XMLParse parse = new XMLParse();
        parse.showPhoneInfo();
    }
}
